#ifndef __ENCODER_H__
#define __ENCODER_H__

#include "Arduino.h"
#include <SimpleKalmanFilter.h>
#include <ESP32Encoder.h>

/// bellow are motor Parameters///////////

#define Diameter_67 67.0       // 轮子直径
#define EncoderMultiples 2.0   // 编码器倍频
#define Encoder_precision 11.0 // 编码器分辨率，有地方也叫编码器线数
#define Reduction_Ratio 19.0   // 电机减速比
#define Perimeter 210.4867     // 周长

/// ////////////////////////////////

class WheelEncoder : public SimpleKalmanFilter, public ESP32Encoder
{
public:
    WheelEncoder(int input_a, int input_b);
    WheelEncoder(int input_a, int input_b,bool change_dir);
    void init_whell_param(float wheel_d = Diameter_67, float encoder_multiples = EncoderMultiples, float encoder_precision = Encoder_precision, float reduction_ratio = Reduction_Ratio);
    double get_speed_raw();
    double get_speed();
    void init_hardware();
    float get_distance();
    void encoder_reset();
    void encoder_deinit();
    long get_cnt();
    bool change_dir=false;
 
private:

    int encoder_cnt = 0;
    bool _usemy_int = false;
    float _wheel_diameter, _encoder_multiples, _encoder_precision, _reduction_ratio;
    long last_speed_update_time;
    int last_count;
};
#endif